<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <title>盛筑OA协同办公系统</title>
    <link rel="stylesheet" href="./static/lib/fontawesome/css/font-awesome.min.css" />
    <link rel="stylesheet" href="./static/lib/layui/css/layui.css">
    <link rel="stylesheet" href="./static/kaige/css/index.css?s=6162" />
    <link rel="stylesheet" href="./static/kaige/css/chat.css?s=6165" />
</head>

<body class="skin-blue">
    <div class="loading-index">盛筑智能办公系统 > 加载中...</div>
    <header class="main-header layui-hide">
        <a href="index.html" class="logo">
            <span class="logo-mini" title="盛筑OA协同办公系统">盛筑</span>
            <span class="logo-lg">盛筑OA协同办公系统</span>
        </a>
        <a href="#" class="sidebar-toggle sideico-t2" title="切换导航">
            <span class="sr-only">切换导航</span>
        </a>
        <div class="navtab">
            <div class="task-tab-btn overleftbtn"><i class="layui-icon layui-icon-left"></i></div>
            <div class="taskbox">
                <ul class="ml-taskbar-task"></ul>
            </div>
            <div class="task-tab-btn overrightbtn"><i class="layui-icon layui-icon-right"></i></div>
            <div class="task-tab-btn overmorebtn" id="overmorebtn"><i class="layui-icon layui-icon-more-vertical"></i>
            </div>
        </div>
        <div class="user-info-box">
            <ul class="user-info-content">
                <li>
                    <a href="#" class="user-info-toggle">
                        <img src="" class="user-avatar" alt="用户头像">
                    </a>
                    <ul class="user-info-menu">
                        <li class="user-header">
                            <img src="" class="img-circle" alt="用户头像">
                            <p>
                                <span>昵称</span><small>恺哥</small>
                                <span>登录次数</span><small>251</small>
                                <span>上次IP</span><small>117.26.0.36</small>
                                <span>上次登录</span><small>2022-06-13 11:34</small>
                            </p>
                        </li>
                        <li class="user-footer">
                            <div class="pull-left">
                                <a id="edit-pass" class="btn btn-default btn-flat">修改密码</a>
                            </div>
                            <div class="pull-right">
                                <a id="logout" class="btn btn-default btn-flat">退出系统</a>
                            </div>
                        </li>
                    </ul>
                </li>
                <li>
                    <a href="javascript:;" class="btn-fullscreen" title="全屏模式切换"><i class="fa fa-expand"></i></a>
                </li>
            </ul>
        </div>
    </header>

    <aside class="main-sidebar layui-hide">
        <div class="navmenu">
            <ul class="nm-ul" id="nav_left_menu"></ul>
        </div>
        <section class="ml-m-r">
            <div class="layui-side-scroll">
                <ul class="ml-menu layui-nav layui-nav-tree"></ul>
            </div>
        </section>
    </aside>

    <div class="content-wrapper layui-hide"></div>

    <footer class="main-footer layui-hide">
        <div class="pull-right hidden-xs"><b>版本</b>&nbsp;v1.0.0</div>©2022&nbsp;泉州市盛筑信息科技有限公司&nbsp;版权所有
    </footer>

    <script src="./static/lib/jquery/jquery.min.js"></script>
    <script src="./static/kaige/js/qs.js"></script>
    <script src="./static/kaige/js/cry/md5.js"></script>
    <script src="./static/kaige/js/cry/sha1.js"></script>
    <script src="./static/kaige/js/szconfig.js"></script>
    <script src="./static/kaige/js/szoa.js"></script>
    <script src="./static/lib/layui/layui.js"></script>
    <script src="./static/kaige/js/szimcomm.js"></script>
    <script src="./static/kaige/js/WebSocket.js"></script>
    <script>
        layui.config({
            base: './static/kaige/layuiextend/'
        }).use(['element', 'layer', 'kaigehome', 'oawin', 'oamenu', 'kaige', 'szim'], function () {
            var element = layui.element, $ = layui.jquery, layer = layui.layer, kaigehome = layui.kaigehome, oawin = layui.oawin, oamenu = layui.oamenu, kaige = layui.kaige;
            var szim = layui.szim;
            window.load_add = function () {
                $dom = '<div class="layui-progress" lay-filter="index-loading" lay-showPercent="yes"><div class="layui-progress-bar" lay-percent="0%"></div></div>';
                $('body').append($dom);
                var starnum = 0;
                var load_it = setInterval(function () {
                    starnum += 1;
                    element.progress('index-loading', starnum + '%');
                    if (starnum >= 99) {
                        clearInterval(load_it);
                    } else if (starnum < 80) {
                        starnum += 10;
                    }
                }, 10);
            }
            window.load_del = function () { $('.layui-progress').remove() };

            window.kaige_page = {
                logout_url: '/index/logout',
                welcome: './pages/welcome.html',
                menus: [],
                leftmenu: [],
            };
            window.openview = function (d) { // 保留--为了兼容部份调用
                setTimeout(function () {
                    window.indexopenlayerid = kaige.open({
                        id: 'kaige',
                        url: (szoa.client.path || '') + d.url + '&formpage=index',
                        title: '<i class="fa fa-eye"></i> ' + d.title,
                    });
                }, 20);
            }
            //取数据
            szoa.ajax({
                url: '/index/index',
                type: 'GET',
                async: false,
                success: function (result) {
                    if (result.status) {
                        var d = result.data;
                        if (d.title) document.title = d.title;
                        if (d.site_name) {
                            $('.logo').html('<span class="logo-mini" title="' + d.site_name + '">' + (d.site_name.slice(0, 2)) + '</span><span class="logo-lg">' + d.site_name + '</span>');
                        }
                        if (d.app_version && d.site_copy) {
                            $('footer').html('<div class="pull-right hidden-xs"><b>版本</b> ' + d.app_version + '</div>' + d.site_copy + '');
                        }
                        if (typeof (d.menus) == 'string') {
                            d.menus = JSON.parse(d.menus);
                            kaige_page.menus = d.menus;
                        }
                        if (typeof (d.leftmenu) == 'string') {
                            d.leftmenu = JSON.parse(d.leftmenu);
                            kaige_page.leftmenu = d.leftmenu;
                        }
                        if (typeof (d.config) === 'object') {
                            window.kaigeUserInfo = d.config;
                            var uo = $('.user-header');
                            uo.find('img').attr('src', d.config.avatar);
                            $('.user-avatar').attr('src', d.config.avatar);
                            uo.find('p').html('<span>昵称</span><small>' + (d.config.nickname ? d.config.nickname : d.config.username) + '</small><span>登录次数</span><small>' + d.config.login_num + '</small><span>上次IP</span><small>' + d.config.last_ip + '</small><span>上次登录</span><small>' + d.config.last_time + '</small>');
                        }
                        window.kaige_page.dict = d.dict;
                        window.nowuser = d.config;
                        // console.log(window.kaige_page);
                        start();
                    }
                }
            });

            //取完数据再执行
            function start() {
                if (szoa.getToken()) {
                    $('header').removeClass('layui-hide');
                    $('aside').removeClass('layui-hide');
                    $('.content-wrapper').removeClass('layui-hide');
                    $('footer').removeClass('layui-hide');
                    $('.loading-index').remove();
                    oawin.init();
                    oamenu.init();
                    szim.config({
                        initUrl: '/im.chat/sziminit',
                        qunUrl: '/im.chat/szimqun',
                        userhisUrl: '/im.chat/getUserChatObjList',
                        delmsgUrl: '/im.chat/delmessage',
                        qunhisUrl: '/im.chat/getUserGroupChatList',
                        is_voice: 1, //是否开启声音
                    });
                    createSocket();

                    // 接收消息
                    var pingnum = 0;
                    function getsocketData(e) {
                        var recedata = e && e.detail.data;
                        recedata = JSON.parse(recedata);
                        // console.log('-----接收消息----------');
                        // console.log(recedata);
                        switch (recedata.type) {
                            case 'connect':
                                //连接成功后，进行绑定
                                sendWSPush({ type: 'bind', formId: kaigeUserInfo.id, token: szoa.getCache(szoa.client.tokenKey) });
                                break;
                            case 'ping':
                                if(pingnum > 0){
                                    // 需要定时的任务如下：
                                    sendWSPush({ type: 'flowhis', formId: kaigeUserInfo.id });
                                }
                                pingnum++;
                                break;
                            case 'bind':
                                setTimeout(function(){
                                    sendWSPush({ type: 'flowhis', formId: kaigeUserInfo.id });
                                },300);
                                break;
                            case 'chat': //聊天
                                szim.getMessage(recedata);
                                break;
                            case 'flowhis': //流程离线历史
                                var rd = recedata.list;
                                if (rd && rd.length > 0) {
                                    layui.each(rd, function (i9, e9) {
                                        szim.getMessage(e9);
                                    });
                                }
                                var smg = recedata.sysmsg;
                                if (smg && smg.length > 0) {
                                    layui.each(smg, function (i9, e9) {
                                        szim.getMessage(e9);
                                    });
                                }
                                break;
                        }
                    }
                    // 注册监听事件
                    window.addEventListener('onmessageWS', getsocketData);
                } else {
                    window.location.href = './pages/login.html';
                }
            }
        });
    </script>
</body>

</html>